﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
using BLL;
namespace AGVControlSystemPro
{
    public partial class FrmCallView : Form
    {
        public FrmCallView()
        {
            InitializeComponent();
            //呼叫显示格式
            this.dgvStandbyCall.AutoGenerateColumns = false;
            new Common.DataGridViewStyle().DgvStyle3(this.dgvStandbyCall);
            //以防数据为空，导致异常
            if (CommonMethods.ListPreCall != null && CommonMethods.ListPreCall.Count != 0) this.dgvStandbyCall.DataSource = CommonMethods.ListPreCall;
            this.timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (CommonMethods.StatndbyCallDisplayFlag)
            {
                CommonMethods.StatndbyCallDisplayFlag = false;//避免一直更新              
                new RemoteIOManager().AddStandbyCall(this.dgvStandbyCall, CommonMethods.ListPreCall);
            }
        }

        private void dgvStandbyCall_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
           Common.DataGridViewStyle.DgvRowPostPaint(this.dgvStandbyCall, e);
        }

        private void dgvStandbyCall_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (this.dgvStandbyCall.CurrentRow != null && this.dgvStandbyCall.Rows.Count != 0)
                {
                    DataGridViewColumn column = dgvStandbyCall.Columns[e.ColumnIndex];
                   
                    if (column is DataGridViewButtonColumn)
                    {
                        
                        //删除数据里面对应的数据          
                        new RemoteIOManager().DeleteUnfinishCall(CommonMethods.ListPreCall[e.RowIndex]);
                        CommonMethods.ListPreCall.RemoveAt(e.RowIndex); //删除数据
                        this.dgvStandbyCall.DataSource = null;
                        this.dgvStandbyCall.DataSource = CommonMethods.ListPreCall;
                    }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("删除失败，详细信息：" + ex.Message);
            }
        }

    }
}
